package com.hubox;

import com.hubox.vo.UserStatusVo;
import com.hubox.vo.UserVo;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Length;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Validated
@RestController
@Slf4j
@RequestMapping("valid")
public class UserController {
    @RequestMapping("/sample")
    public ResponseEntity sample(@Validated @RequestBody UserVo userVo) {
        log.info("accept request: {}", userVo);
        return ResponseEntity.ok().build();
    }

    /**
     * 只校验UserVo里面groups={ValidationGroups.Create.class}的字段的值
     *
     * @param userVo
     * @return
     */
    @RequestMapping("/create")
    public ResponseEntity create(@Validated(ValidationGroups.Create.class) @RequestBody UserVo userVo) {
        log.info("accept request: {}", userVo);
        return ResponseEntity.ok().build();
    }

    /**
     * 只校验UserVo里面groups={ValidationGroups.Update.class}的字段的值
     *
     * @param userVo
     * @return
     */
    @RequestMapping("/update")
    public ResponseEntity update(@Validated(ValidationGroups.Update.class) @RequestBody UserVo userVo) {
        log.info("accept request: {}", userVo);
        return ResponseEntity.ok().build();
    }

    @RequestMapping("/nested")
    public ResponseEntity nested(@Validated @RequestBody UserStatusVo vo) {
        log.info("accept request: {}", vo);
        return ResponseEntity.ok().build();
    }

}
